package daobeauty.interceptor.invoke.parser.operator;

import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import daobeauty.util.Stack;

public class IsNotNullOperator implements Operator {
	private String propertyName;
	
	public IsNotNullOperator(String propertyName) {
		this.propertyName = propertyName;
	}

	public Criterion createCriterion(Stack argumentStack) {
		return Restrictions.isNotNull(propertyName);
	}
	
	public String toHqlQuery(Stack argumentStack, List usedArguments){
		return "d."+propertyName+" IS NOT NULL";
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((propertyName == null) ? 0 : propertyName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final IsNotNullOperator other = (IsNotNullOperator) obj;
		if (propertyName == null) {
			if (other.propertyName != null)
				return false;
		} else if (!propertyName.equals(other.propertyName))
			return false;
		return true;
	}

	public int getAmountArguments() {
		return 0;
	}

	public int getTotalAmountArguments() {
		return 0;
	}

	public String toTotalString() {
		return propertyName+" ISNOTNULL";
	}
	
	public String toString(){
		return toTotalString();
	}
}
